<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:nwisdocs="http://wales.nhs.uk/nwis/docs"
	exclude-result-prefixes="xs xsi">

  <xsl:template match="nwisdocs:PatientDetails">
    <div class="boxed-section" id="{local-name()}">
      <h2>Patient details</h2>

      <label>Patient Name</label>
      <span>
        <xsl:value-of select="nwisdocs:Demographics/nwisdocs:FormalName/nwisdocs:StructuredName/nwisdocs:Title"/>
        <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
        <xsl:value-of select="nwisdocs:Demographics/nwisdocs:FormalName/nwisdocs:StructuredName/nwisdocs:GivenName"/>
        <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
        <xsl:value-of select="nwisdocs:Demographics/nwisdocs:FormalName/nwisdocs:StructuredName/nwisdocs:FamilyName"/>
      </span>

      <br />

      <label>Date of birth</label>
      <span>
        <xsl:choose>
          <xsl:when test="nwisdocs:Demographics/nwisdocs:DateOfBirth != ''">
            <xsl:call-template name="standard_date">
              <xsl:with-param name="date" select="nwisdocs:Demographics/nwisdocs:DateOfBirth"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            Unknown
          </xsl:otherwise>
        </xsl:choose>
      </span>

      <br />

      <label>Gender</label>
      <span>
        <xsl:value-of select="nwisdocs:Demographics/nwisdocs:Gender"/>

      </span>

      <br />

      <label>NHS Number</label>
      <span>
        <xsl:value-of select="nwisdocs:NHSnumber/nwisdocs:IdValue"/>
      </span>

      <br />

      <xsl:for-each  select="nwisdocs:PatientId">
        <label>Hospital No:</label>
        <span>
         <xsl:value-of select="nwisdocs:IdValue"/>
        </span>
        <br />
      </xsl:for-each>

      <label>Patient Address</label>
      <span>
        <xsl:for-each select="nwisdocs:Demographics/nwisdocs:Address/nwisdocs:StructuredAddress/nwisdocs:AddressLine">
          <xsl:value-of select="."/>
          <br />  
        </xsl:for-each>
        <xsl:value-of select="nwisdocs:Demographics/nwisdocs:Address/nwisdocs:PostCode"/>
      </span>
    
    </div>
  </xsl:template>

</xsl:stylesheet>
